#!/bin/bash

grep "cyclehead" $1 | cut -d "," -f 1 | cut -d ":" -f 1,3 | sort | uniq > idandheads

echo loopheads:
cat idandheads | cut -d ":" -f 2 | sed -e "s/^main#/__user_main#/g"

echo loopmap:

#echo idandheads: $idandheads

for ih in $(cat idandheads); do
   i=$(echo $ih | cut -d ":" -f 1)
   h=$(echo $ih | cut -d ":" -f 2)
   echo $ih: >&2
  grep "^$i" $1 | grep "cyclehead\|cycle" | cut -d ":" -f 3- | tr "," "\n" | sort | uniq | sed -e "s/$/ $h/g" | sed -e "s/^main#/__user_main#/g"
done
